/**
 * Copyright 2011-2011 - Members of the Chaupal Community
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package net.chaupal.Impl.v1.Proof.ConfirmationProtocol;

public final class CPEvent implements Comparable<CPEvent> {

    private final CPMessageType messageType;
    private final CPMessageArrivalTiming arrivalTiming;

    private final String shortCode;

    public CPEvent(CPMessageType inType, CPMessageArrivalTiming inAT) {

        messageType = inType;
        arrivalTiming = inAT;

        shortCode = messageType.getCode() + arrivalTiming.getCode();

    }

    @Override
    @SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CPEvent other = (CPEvent) obj;
        if ((this.shortCode == null) ? (other.shortCode != null) : !this.shortCode.equals(other.shortCode)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 67 * hash + (this.shortCode != null ? this.shortCode.hashCode() : 0);
        return hash;
    }

    public String getShortCode() {
        return shortCode;
    }

    public CPMessageType getMessageType() {
        return messageType;
    }

    public CPMessageArrivalTiming getMessageArrivalTiming() {
        return arrivalTiming;
    }

    @Override
    @SuppressWarnings(value = "AccessingNonPublicFieldOfAnotherObject")
    public int compareTo(CPEvent o) {
        
        if (o == null) return 1;
        if (o == this) return 0;

        int tmp = messageType.compareTo(o.messageType);
        if (tmp != 0) return tmp;
        
        return this.arrivalTiming.compareTo(o.arrivalTiming);
        
    }

}
